﻿using Microsoft.EntityFrameworkCore;
using ZH.GPT.Infrastructures;
using System;
using System.Collections.Generic;
using System.Text;

namespace ZH.GPT.Infrastructures.Extension
{
    /// <summary>
    /// DbContext扩展
    /// </summary>
    public static class DbContextExtend
    { 
        /// <summary>
        /// 转换读写DbContext
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="conn"></param>
        /// <returns></returns>
        public static DbContext GetDbContext(this DbContext dbContext, string conn)
        {
            if (dbContext is MainDBContext)
            {
                var context= (MainDBContext)dbContext; // context 是 EFCoreContext 实例；
                return context.ToDbContext(conn);
            }
            else
                throw new Exception();
        }
    }
}
